# !/usr/bin/env python
# -*- coding: utf-8 -*-
# ///////////////////////////////////////////////////////////////
# @File    :   dragImage.py
# @Time    :   2024/08/21 10:40:11
# @Author  :   kai.luo
# @Version :   1.0.0
# @Desc    :   对图片进行拖拽
# ///////////////////////////////////////////////////////////////
# type: ignore
from PySide6.QtWidgets import *
from PySide6.QtGui import *
from PySide6.QtCore import *


class DragImage(QGraphicsView):
    def __init__(self, mainUI):
        super().__init__()
        self.mainUI = mainUI

    def setDragMode(self):
        # # 隐藏滑动条
        self.mainUI.graphicsView.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.mainUI.graphicsView.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.mainUI.graphicsView.setDragMode(QGraphicsView.ScrollHandDrag)

    def setZoomMode(self):
        # Enable zoom using the wheel
        self.mainUI.graphicsView.setRenderHint(QPainter.Antialiasing)
        self.mainUI.graphicsView.setRenderHint(QPainter.SmoothPixmapTransform)

    # def wheelEvent(self, event):
    #     # Handle zoom
    #     factor = 0.8
    #     if event.angleDelta().y() < 0:
    #         factor = 1.0 / factor
    #     self.mainUI.graphicsView.scale(factor, factor)

    def wheelEvent(self, e: QWheelEvent):
        """鼠标缩放"""
        if e.angleDelta().y() > 0:
            self.scale(1.1, 1.1)
        else:
            self.scale(1 / 1.1, 1 / 1.1)
        self.setTransformationAnchor(self.ViewportAnchor.AnchorUnderMouse)
